package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.GetAllAgentMarkupConfigBean;
import com.ymatou.iapi.godmch.parameter.SetMarkupConfigBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.GetAllAgentMarkupConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.MarkupConfig;
import com.ymttest.database.model.godmch.interactionstate;
import com.ymttest.database.sqlwapper.godmch.MarkupconfigWapper;
/**
*查询所有代理商加价配置Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAllAgentMarkupConfig{
	private static GetAllAgentMarkupConfigBean bean;
	private static GetAllAgentMarkupConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询所有代理商加价配置Test");
	}

	@Before
	public void caseUp() {
		bean=new GetAllAgentMarkupConfigBean();
		call=new GetAllAgentMarkupConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws InterruptedException
	{
		List<MarkupConfig> return_lst=call.getList();
		List<MarkupConfig> configs = new MarkupconfigWapper().selectBySupplierId(bean.getSupplierId());
		//验证
		Logger.verifyEquals("200", call.getString("status"), "验证code");
		Logger.verifyEquals(true,return_lst.size()==configs.size(), "验证返回的数据与数据库查询的一致");
		for(int i=0;i<configs.size();i++)
		{
			MarkupConfig return_config=return_lst.get(i);
			MarkupConfig config=configs.get(i);
			Logger.verifyEquals(return_config.getMarkupType(), config.getMarkupType(), "验证markupType");
			Logger.verifyEquals(return_config.getPercentage().stripTrailingZeros().toPlainString(), config.getPercentage().stripTrailingZeros().toPlainString(), "验证percentage");
			Logger.verifyEquals(return_config.getDecimalType(), config.getDecimalType(), "验证decimalType");
			Logger.verifyEquals(return_config.getOnSaleType(),config.getOnSaleType(), "验证onSaleType");
			Logger.verifyEquals(return_config.getRefreshProduct(), config.getRefreshProduct(), "验证refreshProduct");
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAllAgentMarkupConfig_001() {
		Logger.start(true,"查询所有代理商加价配置-供货商未设置-成功");
		try {
//			SetMarkupConfigBean SetMarkupConfigBean=GodmchManageCallService.initSetMarkupConfigV2(null, null);
//			GodmchManageCallService.SetMarketupBeanCall(SetMarkupConfigBean);
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(mchId_channl);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));
			
			bean.setSupplierId(mchId_channl);
			call.setData(bean);
			call.callService();		
			
			List<MarkupConfig> return_lst=call.getList();
			Logger.verifyEquals("200", call.getString("status"), "验证code");
			Logger.verifyEquals(0,return_lst.size(), "验证返回空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAllAgentMarkupConfig_002() {
		Logger.start(true,"查询所有代理商加价配置-供货商已设置-成功");
		try {
			SetMarkupConfigBean SetMarkupConfigBean=GodmchManageCallService.initSetMarkupConfigV2(null, null);
			GodmchManageCallService.SetMarketupBeanCall(SetMarkupConfigBean);
			bean.setSupplierId(SetMarkupConfigBean.getSupplierId().get(0));
			call.setData(bean);
			call.callService();			
			check_verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAllAgentMarkupConfig_003() {
		Logger.start(true,"查询所有代理商加价配置-供货商不存在-成功");
		try {
			
			bean.setSupplierId(121321);
			call.setData(bean);
			call.callService();			
			List<MarkupConfig> return_lst=call.getList();
			Logger.verifyEquals("200", call.getString("status"), "验证code");
			Logger.verifyEquals(0,return_lst.size(), "验证返回空");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}